//
//  BLSettingTableViewController.m
//  百思不得姐
//
//  Created by hbl on 16/3/24.
//  Copyright © 2016年 hbl. All rights reserved.
//

#import "BLSettingTableViewController.h"
#import <YYWebImageManager.h>
#import <YYImageCache.h>
#import <YYDiskCache.h>
#import "SVProgressHUD.h"
@interface BLSettingTableViewController ()
@property (nonatomic, assign)float disk;
@end

@implementation BLSettingTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = @"清除缓存";
    YYImageCache *cache = [YYWebImageManager sharedManager].cache;
    self.disk = (float)cache.diskCache.totalCost/(1024 * 1024);
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%.2fM",self.disk];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    YYImageCache *cache = [YYWebImageManager sharedManager].cache;
    [cache.diskCache removeAllObjects];
    
    [cache.diskCache removeAllObjectsWithProgressBlock:nil endBlock:^(BOOL error) {
        if (!error) {
           
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [self.tableView reloadData];
            }];
            [SVProgressHUD showSuccessWithStatus:@"清除成功！"];
            
        }
    }];

}

@end
